﻿using AutoMapper;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using RongCloudSms.AutoMapper;
using RongCloudSms.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RongCloudSms.Configuration
{
    public static class RepositoryBuilderExtensions
    {
        /// <summary>
        /// 添加仓储配置
        /// </summary>
        /// <typeparam name="TContext"></typeparam>
        /// <param name="server"><see cref="RepositoryBuilder"/></param>
        /// <param name="storeOptionsAction">仓储配置设置函数</param>
        /// <returns></returns>
        public static IServiceCollection AddMongoDBRepository(this IServiceCollection service, IConfiguration configuration)
        {
            Mapper.Initialize(cfg =>
            {
                cfg.AddProfile<RongCloudProfile>();
            });
           var option= configuration.Get<RongCloudOption>();
            service.AddHttpClient("rongcloud", c =>
            {
                c.BaseAddress = new Uri(option.Url);
            });
            service.AddOptions().Configure<RongCloudOption>(configuration);
            service.AddSingleton<IRongCloudService, RongCloudService>();
            return service;
        }
    }
}
